package br.com.sovi.gwt.client;

import br.com.sovi.gwt.client.component.centerpanel.CenterPanel;
import br.com.sovi.gwt.client.component.mainmenu.MainMenu;
import br.com.sovi.gwt.client.images.Images;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.util.CSS;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SoviPrototipo implements EntryPoint {

	public void onModuleLoad() {
		CSS.swapStyleSheet("theme", "extjs/resources/css/xtheme-darkgray.css");

		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setPaddings(2);
		panel.setLayout(new FitLayout());

		panel.add(mainBorderPanel());

		new Viewport(panel);
	}

	private Panel mainBorderPanel() {
		Panel borderPanel = new Panel();
		borderPanel.setLayout(new BorderLayout());

		Panel topPanel = new Panel();
		topPanel.addClass("topPanel");
		topPanel.setHeight(80);

		Images images = ImagesImpl.get();
		
		StringBuilder sb = new StringBuilder("<div class=\"topPanel\">");
		if (images != null) {
			sb.append(images.sovi_topo().getHTML());
		}
		sb.append("</div>");

		HTML html = new HTML(sb.toString());
		topPanel.add(html);

		borderPanel.add(topPanel, new BorderLayoutData(RegionPosition.NORTH));
		borderPanel.add(createBottomPanel(), new BorderLayoutData(
				RegionPosition.CENTER));

		return borderPanel;
	}

	private Panel createBottomPanel() {
		final Panel borderPanel = new Panel();
		borderPanel.setLayout(new BorderLayout());

		MenuLateralPanel menuLateralPanel = new MenuLateralPanel();
		menuLateralPanel.collapse();

		CenterPanel centerPanel = new CenterPanel();
		centerPanel.setLayout(new FitLayout());

		borderPanel.add(new MainMenu(menuLateralPanel, centerPanel),
				new BorderLayoutData(RegionPosition.NORTH));
		borderPanel.add(menuLateralPanel, new BorderLayoutData(
				RegionPosition.WEST));
		borderPanel.add(centerPanel,
				new BorderLayoutData(RegionPosition.CENTER));

		return borderPanel;
	}

}
